package cn.edu.hstc.wm.ui;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import cn.edu.hstc.wm.ui.base.BaseActivity;
import cn.edu.hstc.wm.utils.StringUtils;
import cn.edu.hstc.wm.widget.CustomToast;

import cn.edu.hstc.wm.AppApplication;
import cn.edu.hstc.wm.AppConfigs;
import cn.edu.hstc.wm.R;

/**
 * @ClassName: AboutActivity
 * @Description: 关于 app 说明的界面 TODO 实现使用微博关注,微信关注的方式
 * 
 * @ModificationHistory
 */
public class AboutApp extends BaseActivity implements OnClickListener {

	private TextView mWeixin;
	private TextView mWeibo;

	public void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		setContentView(R.layout.about);

		initActionbar();
		initView();
	}

	private void initView() {
		mWeibo = (TextView) findViewById(R.id.tv_contact_sina);
		mWeixin = (TextView) findViewById(R.id.tv_contact_weixin);

		String htmlLinkWeixin = "<a href=\"http://weixin.qq.com\"> " + getResources().getString(R.string.contact_weixin) + "</a>";
		String htmlLinkWeibo = "<a href=\"#\"> " + getResources().getString(R.string.contact_sina) + "</a>";

		mWeixin.setText(Html.fromHtml(htmlLinkWeixin));
		mWeixin.setMovementMethod(LinkMovementMethod.getInstance());
		mWeibo.setText(Html.fromHtml(htmlLinkWeibo));
		mWeibo.setOnClickListener(this);

		((TextView) findViewById(R.id.tv_about_info)).setText(String.format(getString(R.string.app_about), ((AppApplication) getApplication()).getVersionName()));

	}

	private void initActionbar() {
		ImageButton backButton = (ImageButton) findViewById(R.id.ib_actionbar_back);
		TextView titleView = (TextView) findViewById(R.id.tv_actionbar_title);
		ImageButton shareButton = (ImageButton) findViewById(R.id.ib_actionbar_share);

		backButton.setOnClickListener(this);
		titleView.setText("关于我们");
		shareButton.setVisibility(View.VISIBLE);
		shareButton.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {

		case R.id.ib_actionbar_back:
			finish();
			break;

		case R.id.ib_actionbar_share:
			CustomToast.make(this).setText("分享").show();
			Intent shareIntent = new Intent();
			shareIntent.setAction(Intent.ACTION_SEND);
			shareIntent.putExtra(Intent.EXTRA_TEXT, "我正在使用\"我要叫外卖\"这款软件呢,非常不错,大家快来下载试试吧!\n下载地址: " + AppConfigs.DOWNLOAD_URL);
			shareIntent.setType("text/plain");
			startActivity(Intent.createChooser(shareIntent, "分享到..."));
			break;

		case R.id.tv_contact_sina:
			Intent intent = new Intent();
			intent.setAction("android.intent.action.VIEW");
			Uri content_url = Uri.parse("http://weibo.com/2866750083/profile?topnav=1&wvr=5");
			intent.setData(content_url);
			startActivity(intent);
			break;
		default:
			break;
		}

	}
}
